package com.das.mechanic_alone.mvp.presenter.alone;

import com.das.mechanic_alone.mvp.contract.alone.X3WebAloneServiceContract;
import com.das.mechanic_base.base.X3BasePresenter;
import com.das.mechanic_base.bean.alone.NewServiceHeaderBean;
import com.das.mechanic_base.bean.greendao.AloneServiceListBean;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.utils.X3StringUtils;

import java.util.ArrayList;
import java.util.List;

public class X3WebAloneServicePresenter extends X3BasePresenter<X3WebAloneServiceContract.View> implements X3WebAloneServiceContract.Presenter{

    @Override
    public void getServiceBaseInfo(long carId, boolean isJump) {
        NetWorkHttp.getApi().getServiceListByCarId(carId)
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<NewServiceHeaderBean>() {
                    @Override
                    protected void onDone(NewServiceHeaderBean serviceHeaderBeans) {
                        mView.getServiceInfo(serviceHeaderBeans,isJump);
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    @Override
    public void getDetectionServiceList() {

    }

    @Override
    public void saveDetectionService(List<AloneServiceListBean> mList) {
        if (X3StringUtils.isListEmpty(mList)) {
            mList = new ArrayList<>();
        }
        NetWorkHttp.getApi().saveDetectionServiceList(mList,mView.providerWorkBaseId())
                .compose(mView.bindToLife())
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .subscribe(new HttpCallBack<Object>() {
                    @Override
                    protected void onDone(Object o) {
//                        mView.searchAloneCache();
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    @Override
    public void saveCarMaintenancePlan(NewServiceHeaderBean bean) {
        NetWorkHttp.getApi().saveCarMaintenancePlan(bean)
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<Object>() {
                    @Override
                    protected void onDone(Object object) {
                        mView.saveCarMaintenancePlanSus();
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }
}
